package au.com.iglootech.TaxTimeToolTip.ui.feerate;

import au.com.iglootech.TaxTimeToolTip.style.TaxTimeToolTipStyle;

import com.vaadin.data.Item;
import com.vaadin.data.validator.DoubleValidator;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;

public class FeeRateFieldFactory extends DefaultFieldFactory {
	@Override
	public Field createField(Item item, Object propertyId, Component uiContext) {
		Field f;

		// Use the super class to create a suitable field base on the
		// property type.
		f = super.createField(item, propertyId, uiContext);

		if ("rate".equals(propertyId)) {
			TextField tf = (TextField) f;
			tf.setRequired(true);
			tf.setRequiredError("Enter a floating-point value");
			tf.setNullRepresentation("");
			tf.setWidth(TaxTimeToolTipStyle.COMMON_FIELD_WIDTH);
			tf.addValidator(new DoubleValidator(
					"Not a double!"));
		} 

		return f;
	}
}
